package arithmetic.leetCode.yi;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * title:给定两个字符串，确定一个字符串重新排序后，能否变成另外一个字符串
 * User: yilin
 * Date: 2019-04-09
 * Time: 17:44
 */
public class StringCompare1 {


    /**
     * 思路：
     * 1：字符串的长度必须相等
     * 2:通过各个字符串出现的次数进行比较
     *
     * @param str1
     * @param str2
     * @return
     */
    public static boolean compareString(String str1, String str2) {
        if (str1.length() != str2.length()) {
            return false;
        }
        int letter[] = new int[256];
        for (char c : str1.toCharArray()) {
            letter[c]++;

        }

        for (char c : str2.toCharArray()) {
            letter[c]--;
            if (letter[c] < 0) {
                return false;
            }
        }


        return true;
    }

    public static void main(String[] args) {
        System.out.println(compareString("agcdbfd", "dgffacb"));
    }

}
